package Aleehot100;

/**
 * ClassName: c079
 * Package: Aleehot100
 * Description: 45. 跳跃游戏 II
 *
 * @Author BCXJ
 * @Create 2025/9/3 09:08
 * @Version 1.0
 * @Since 1.0
 */
public class c079 {
    public static void main(String[] args) {
        //int[] arr = {2,3,1,1,4};
        int[] arr = {0};
        System.out.println(jump(arr));
    }


    public static int jump(int[] nums) {
        int jumps = 0;
        int farthest = 0;
        int currentEnd = 0;
        int n = nums.length;

        // 遍历数组
        for (int i = 0; i < n - 1; i++) {
            farthest = Math.max(farthest, nums[i] + i);
            if(i == currentEnd) {
                jumps ++;
                currentEnd = farthest;
                if(farthest >= n - 1) {
                    break;
                }
            }
        }
        return jumps;
    }
}
